import api from '@api'

const state = {
  banner: {
    list: []
  },
  shop: {
    list: []
  },
  recommend: {
    list: [],
    isLoad: false
  }
}

const getters = {
  ['getBanner'] (state) {
    return state.banner.list;
  },
  ['getShop'] (state) {
    return state.shop.list
  }
}

const actions = {
  async ['getBannerList'] ({commit}) {
    let { data: { bannerList, StatusCode} } = await api.get('api/v1/Banner/bannerListWap.ashx');
    if(StatusCode == '200') {
      commit('updateBannerList', bannerList);
    }
  },
  async ['getShopList'] ({commit}, {latitude, longitude}) {
    let { data: { warehouseList, StatusCode} } = await api.get('api/v2/Store/storeList.ashx', {latitude, longitude});
    if(StatusCode == '200') {
      commit('updataShop', warehouseList)
    }
  },
  async ['getRecomend'] ({commit}) {

  }
}

const mutations = {
  ['updateBannerList'] (state, banner) {
    state.banner.list = banner
  },
  ['updataShop'] (state, shop) {
    state.shop.list = shop
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
